<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/base.css">
    <script src="/js/jquery-3.7.1.min.js"></script>
    <script src="/js/util.js"></script>
    <style>
        body {
            background-color: lightskyblue;
            display: flex;
        }

        .container {
            margin: auto;
            width: 360px;
            max-height: 300px;
            padding: 20px;
            background-color: rgba(255, 255, 255, 1);
            border-radius: 6px;
            box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.1);
        }

        h2 {
            text-align: center;
            font-size: 24px;
            letter-spacing: 8px;
            font-weight: 700;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>欢注册博客</h2>
    <form id="login-from" class="form" action="">
        <div class="form-item">
            <label>用户名：</label>
            <input type="text" name="username" placeholder="请输入用户名">
        </div>
        <div class="form-item">
            <label >密码：</label>
            <input type="password" name="password" placeholder="请输入密码">
        </div>
        <div class="form-item">
            <label >密码：</label>
            <input type="password" name="rePassword" placeholder="请输入密码">
        </div>
        <div class="form-item">
            <button class="bg1" type="submit">注册</button>
            <button class="bg1" type="reset">取消</button>
        </div>
    </form>
    <script>
        $('.form').submit(e => {
            e.preventDefault();
            let formData = $util.getFormData('#login-from');
            console.log(formData)
            if (formData.password !== formData.rePassword) {
                alert('密码和确认密码不一致');
                return;
            }
            delete formData.rePassword;
            $util.post('/register', formData).then(res => {
                alert('注册成功');
                window.location.href = '/to/login';
            });
        });
    </script>
</div>
</body>
</html>